找传奇、传世资源到传世资源站!

海康ISC平台delphi签名算法.pas

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

procedure TcsInfoDefine.sigInit(mth,Url:string;var idHttp1:TIdHttp;para:string='');stdcall;
var
  temp,headStr,curTimeStamp,wSigStr,curTime,myContType :string;
  headjo: ISuperobject;
  myD:TDateTime;
  i : Integer;
begin
  myD := now;
  idHttp1.Request.Clear;
  myContType := 'application/json';
  idHttp1.Request.ContentType := myContType;
  idHttp1.Request.CustomHeaders.AddValue('x-ca-signature-headers','x-ca-key,x-ca-timestamp');
  idHttp1.Request.CustomHeaders.AddValue('x-ca-key',Fapp_id);
  idHttp1.Request.Accept := '*/*';
  curTimeStamp := trim(IntToStr(GetJavaTime(myD)));
  idHttp1.Request.CustomHeaders.AddValue('x-ca-timestamp',curTimeStamp);
  curTime := FormatDateTime('yyyy-mm-dd hh:nn:ss',myD);
  idHttp1.Request.CustomHeaders.AddValue('Date',curTime);
  headStr := '{"x-ca-key":"' Fapp_id '","x-ca-timestamp":' curTimeStamp '}';
  headJo := SO(headStr);
  wSigStr := mth #10 '*/*' #10 myContType #10 curTime #10;
  for i := 0 to headJo.AsObject.count-1 do
    wSigStr := wSigStr lowercase(HeadJo.AsObject.GetNames.AsArray[i].AsString ':'
                    trim(headJo.AsObject.GetValues.AsArray[i].AsString)) #10;
  wSigStr := wSigStr Url;
  if trim(para) <> '' then wSigStr := wSigStr '?' para;
  temp := genSigInfo(wSigStr,Fapp_key);
  idHttp1.Request.CustomHeaders.AddValue('x-ca-signature',temp);
end;

function TcsInfoDefine.genSigInfo(const sigStr,sigKey:string):pChar;stdcall;
var
  temp :string;
begin
  temp := THMACUtils<TIdHMACSHA256>.HMAC_Base64(UTF8Encode(sigKey),UTF8Encode(sigStr));
  result := pChar(temp);
end;

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复